package com.publicize.controller;


import com.publicize.commom.commonutils.JwtUtils;
import com.publicize.commom.commonutils.Result;
import com.publicize.entity.User;
import com.publicize.entity.Vo.QueryVo;
import com.publicize.entity.Vo.UserSelectVo;
import com.publicize.service.UserService;
import org.springframework.http.HttpRequest;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 * 用户表 前端控制器
 * </p>
 *
 * @author bs
 * @since 2021-03-04
 */
@RestController
@RequestMapping("/backstage/user")
@CrossOrigin
public class UserController {
    @Resource
    private UserService userService;

    //删除用户
    @PostMapping("deleteUser/{id}")
    public Result deleteManage(@PathVariable("id") String id){
        userService.removeUser(id);
        return Result.ok();
    }

//根据条件查询用户
    @PostMapping("selectUserByCondition")
    public Result selectUserByCondition(@RequestBody UserSelectVo userSelectVo){
        return userService.selectUserByCondition(userSelectVo);
    }
    //根据id添加/移除用户到黑名单
    @PostMapping("BlacklistUser/{id}")
    public Result BlacklistUser(@PathVariable("id") String id){
        Integer is_black=userService.BlacklistUser(id);
        return Result.ok().data("is_black",is_black);
    }
    //删除用户
    @DeleteMapping("deleteUser/{id}")
    public Result deleteUser(@PathVariable("id") String id){
        boolean delete = userService.removeById(id);
        return delete==true?Result.ok():Result.error();
    }
    //根据token获取用户id获取数据
    @GetMapping("getUser")
    public Result getUser(HttpServletRequest httpRequest){
        //获取用户id
        String userId = JwtUtils.getMemberIdByJwtToken(httpRequest);
        User user = userService.getById(userId);
        return Result.ok().data("user",user);
    }
    @PostMapping("selectByCondition")
    public Result selectByCondition(@RequestBody QueryVo queryVo){
        return null;
    }
}

